package com.atguigu.gmall.all.controller;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import com.atguigu.gmall.product.feign.ProductFeignClient;
import org.bouncycastle.math.raw.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping
public class ItemController {
    @Autowired
    private ItemFeignClient itemFeignClient;
    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * sku详情页面
     * @param skuId
     * @param model
     * @return
     */
    @RequestMapping("{skuId}.html")
    public String getItem(@PathVariable Long skuId, Model model){
        //通过skuId 查询skuInfo
        Result<Map> result = itemFeignClient.getSkuDetail(skuId);
        model.addAllAttributes(result.getData());
        return "item/index1";
    }
    @GetMapping(value = "/index")
    public String index(Model model){
        List<JSONObject> baseCategoryList = productFeignClient.getBaseCategoryList();
        model.addAttribute("list",baseCategoryList);
        return "index/index.html";
    }
}
